<?php
/**
 * Created by PhpStorm.
 * User: qinlu
 * Date: 2018/7/19
 * Time: 16:14
 */
namespace Admin\Controller;

//申请退款控制器
use Think\AjaxPage;

class DrawbackController extends BaseController {



    //申请退款列表
    public function drawback_list(){
        $status = array('待处理','通过', '未通过');
        $this->assign('status_array', $status);
        $this->display();
    }

    /**
     *  列表
     */
    public function ajaxDrawbackList(){

        $status = I('status', -1, 'intval');

        $where = array();
        if($status != -1){
            $where['dw.status'] = $status;
        }

        /*$is_shop = 0;
        if ($this->shop_info)
        {
            $where['dw.shop_id'] = $this->shop_info['shop_id'];
            $is_shop = 1;
        }*/

        $key_word = I('key_word') ? trim(I('key_word')) : '';

        if($key_word)
        {
            $where['users.nickname|users.mobile|ord.order_sn'] = array('like', '%'.$key_word.'%');
        }

        $fields = array('dw.id','dw.user_id','dw.order_id','dw.img','dw.create_time','dw.content','dw.money','dw.status',
            'dw.update_time','dw.admin_id','dw.reason','dw.auto_time','dw.real_money',
            'ord.order_id', 'ord.order_sn','ord.shop_id', 'shop.shop_name',
            'shop.shop_user','users.nickname', 'users.mobile'
        );

        $model = M('drawback');
        $count = $model->alias('dw')
            ->field($fields)
            ->join('ln_order ord on dw.order_id = ord.order_id','left')
            ->join('ln_shop shop on ord.shop_id = shop.id','left')
            ->join('ln_users users on dw.user_id = users.user_id','left')
            ->where($where)
            ->count();

        $Page = new AjaxPage($count, 10);
        $show = $Page->show();
        $list = $model->alias('dw')
            ->field($fields)
            ->join('ln_order ord on dw.order_id = ord.order_id','left')
            ->join('ln_shop shop on ord.shop_id = shop.id','left')
            ->join('ln_users users on dw.user_id = users.user_id','left')
            ->where($where)
            ->limit($Page->firstRow . ',' . $Page->listRows)
            ->order('dw.create_time DESC')
            ->select();

        $this->assign('drawbackList',$list);
        $this->assign('page',$show);// 赋值分页输出
        //$this->assign('is_shop', $is_shop);
        $status = array('待处理','允许退款', '不允许退款', '发货', '退款成功', '退款失败');
        $this->assign('status_array', $status);
        $this->display();
    }

    /**
     * 审核退款
     */
    public function editDrawback(){
        $id = I('id', 0, 'intval');
        $drawbackModel = M('drawback');
        $drawback_info = $drawbackModel->where(array('id'=>$id))->find();

        $status = array('待处理','允许退款', '不允许退款', '发货', '退款成功', '退款失败');
        $this->assign('status_array', $status);
        $this->assign('data', $drawback_info);
        $this->display();
    }

}